<?php
require_once("vcl/vcl.inc.php");
require_once("lib/db_connection.php");
require_once("lib/my_library.php");
//Includes
use_unit("comctrls.inc.php");
use_unit("components4phpfull/jtheadercode.inc.php");
use_unit("components4phpfull/jtdivwindow.inc.php");
use_unit("components4phpfull/jtjavascript.inc.php");
use_unit("components4phpfull/jtsitetheme.inc.php");
use_unit("platinumgrid/jtplatinumgrid.inc.php");
use_unit("forms.inc.php");
use_unit("extctrls.inc.php");
use_unit("stdctrls.inc.php");

//Class definition
class admin_user_management extends Page
{
       public $btnReactivate = null;
       public $cmbPackage = null;
       public $Label5 = null;
       public $JSReactivate = null;
       public $hfCompanyId = null;
       public $dtpExpiration = null;
       public $Label4 = null;
       public $lblUsernameReact = null;
       public $JTDivWindowReactivate = null;
       public $Label3 = null;
       public $JTHeaderGrey = null;
       public $Button1 = null;
       public $Image1 = null;
       public $Alert = null;
       public $lblNew = null;
       public $hfCount = null;
       public $btnSearch = null;
       public $edtSearch = null;
       public $Image4 = null;
       public $hfUsername = null;
       public $hfAcctId = null;
       public $lblUsername = null;
       public $Label2 = null;
       public $Label1 = null;
       public $JSShow = null;
       public $btnSave = null;
       public $editPassword = null;
       public $JTActivate = null;
       public $JSActivate = null;
       public $JTManageUsers = null;
       public $JTSiteTheme1 = null;
       function btnReactivateJSClick($sender, $params)
       {

       ?>
       var company_id = document.getElementById("hfCompanyId").value;
       reactivate(company_id);
       document.getElementById('JTDivWindowReactivate').Hide();
       <?php

       }

       function Button1Click($sender, $params)
       {
       $this->Alert->StartVisible=false;


       }


       function admin_user_managementCreate($sender, $params)
       {
       $get_ac = $_GET['ac'];
       $previous_count = $get_ac;

       //SET EXP DATE
       $date = date("Y-m-d");
       $newdate = strtotime ( '+2 month' , strtotime ( $date ) ) ;
       $newdate = date ( 'Y-m-j' , $newdate );
       $this->dtpExpiration->setText($newdate);

       $query_account = "SELECT * FROM accounts_tbl";// where approval=0
       $result_account = mysql_query($query_account);
       $new_count = mysql_num_rows($result_account);

       if($get_ac!=null && $get_ac!='')
       {
       if($previous_count<$new_count)
       {
       /*echo "<script type=text/javascript>
       alert('You have '+".$new_count."+' new accounts to be approved!');
       </script>";*/
       $new = $new_count-$previous_count;
       $this->lblNew->Caption = 'You have'.' '.$new.' '.'new application';
       $this->Alert->StartVisible=true;
       }
       else
       {
       $this->Alert->StartVisible=false;
       }
       }
       header('Refresh: 60; url=admin_manage_users.php?ac='.$new_count);

       }


       function edtSearchJSClick($sender, $params)
       {

       ?>
       //Add your javascript code here
       document.getElementById('edtSearch').value = '';
       <?php

       }

       function admin_user_managementJSLoad($sender, $params)
       {

       ?>
       document.getElementById('JTManageUsers_colitem_hdr_0').width = '160px';
       document.getElementById('JTManageUsers_colitem_hdr_1').width = '65px';
       document.getElementById('JTManageUsers_colitem_hdr_2').width = '130px';
       document.getElementById('JTManageUsers_colitem_hdr_3').width = '110px';
       document.getElementById('JTManageUsers_colitem_hdr_4').width = '65px';
       document.getElementById('JTManageUsers_colitem_hdr_5').width = '110px';
       document.getElementById('JTManageUsers_colitem_hdr_6').width = '70px';

       document.getElementById('JTManageUsers_colitem_body_0').width = '160px';
       document.getElementById('JTManageUsers_colitem_body_1').width = '65px';
       document.getElementById('JTManageUsers_colitem_body_2').width = '130px';
       document.getElementById('JTManageUsers_colitem_body_3').width = '110px';
       document.getElementById('JTManageUsers_colitem_body_4').width = '65px';
       document.getElementById('JTManageUsers_colitem_body_5').width = '110px';
       document.getElementById('JTManageUsers_colitem_body_6').width = '70px';
       <?php

       }

       function btnSaveJSClick($sender, $params)
       {

       ?>
       var acct_id = document.getElementById('hfAcctId').value;
       var username = document.getElementById('hfUsername').value;
       var password = document.getElementById('editPassword').value;
       activate(acct_id,username,password);
       document.getElementById('JTAccount').Hide();
       <?php

       }

       function JTManageUsersShow($sender, $params)
       {
        $arr_acct = array();
        $query_acct = "SELECT * FROM accounts_tbl where (company_name like '%".$this->edtSearch->Text."%'
        or username like '%".$this->edtSearch->Text."%'
        or timestamp like '%".$this->edtSearch->Text."%'
        or activate_date like '%".$this->edtSearch->Text."%') ORDER BY approval ASC, timestamp ASC";
        $result_acct = mysql_query($query_acct) or die("SELECT ACCOUNTS ".mysql_error());
        while($row_acct = mysql_fetch_array($result_acct))
        {
         $flag_admin = $row_acct['admin'];
         if($flag_admin=='0')
         $acct_type = 'User';
         if($flag_admin=='1')
         $acct_type = 'Admin';

         //FOR COMPANY APPROVAL FLAG
         $query_company = "SELECT approval,flag_trial FROM company_tbl WHERE company_id='".$row_acct['company_id']."'";
         $result_company = mysql_query($query_company) or die("SELECT COMPANY APPROVAL ".mysql_error());
         $row_company = mysql_fetch_array($result_company);

         $comp_approve = $row_company['approval'];
         $comp_trial = $row_company['flag_trial'];

         $flag_approve = $row_acct['approval'];
         if($flag_approve=='0' || $comp_approve=='0')
         {
         $activated = "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<img src='image/x.png' style='height:15px;width:15px'/>";
         //$tools = "<span onclick=showDivWindow('".$row_acct['auto_id']."','".$row_acct['username']."') style='text-decoration:underline;cursor:pointer;font-weight:bold'>Activate</span>";

         if($comp_trial=='1')
         $tools = "<img src='image/activate.png' title='Activate Account' onclick=showDivWindow('".$row_acct['auto_id']."','".$row_acct['username']."') style='cursor:pointer;height:30px;width:30px'/>";
         if($comp_trial=='0')
         $tools = "<img src='image/reactivate.png' title='Re-activate Account' onclick=reactivateWindow('".$row_acct['company_id']."','".$row_acct['username']."') style='cursor:pointer;height:30px;width:30px'/>";
         }
         if($flag_approve=='1' && $comp_approve=='1')
         {
         $activated = "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<img src='image/check.png' style='height:15px;width:15px'/>";
         $tools = '';
         }

         //$tools = "<span onclick=activate('".$row_acct['auto_id']."','".$row_acct['username']."') style='text-decoration:underline;cursor:pointer;font-weight:bold'>Activate Account</span>";

         $grey = "<a href='company_registration.php' title=Google rel=gb_page_fs[]>View</a>";
         $company_grey = "<a href=admin_view_company.php?company_id=".$row_acct['company_id']." title='View Company' rel='gb_page_center[409, 310]'>".$row_acct['company_name']."</a>";

         $present_date = date("Y-m-d");
         $my_class = new my_library();

         if($flag_approve=='1' && $comp_approve=='1')
         {
         $days = $my_class->daysDifference($present_date,$row_acct['activate_date']);
         $days = "<br />".$days."&nbsp;days";
         }
         if($flag_approve=='0' || $comp_approve=='0')
         {
          $days = "";
         }

         $arr_acct[] = array(
         'Company'=>$company_grey,
         'Acct Type'=>$acct_type,
         'Username'=>$row_acct['username'],
         'Registration Date'=>$row_acct['timestamp'],
         'Activated'=>$activated.$days,
         'Activation Date'=>$row_acct['activate_date'],
         'Tools'=>$tools
         );
        }
        $this->JTManageUsers->setCellData($arr_acct);
       }

}

global $application;

global $admin_user_management;

//Creates the form
$admin_user_management=new admin_user_management($application);

//Read from resource file
$admin_user_management->loadResource(__FILE__);

//Shows the form
$admin_user_management->show();

?>